package com.zhxy.manager.controller;

import com.alibaba.excel.EasyExcel;
import com.zhxy.manager.entity.EquipmentRepair;
import com.zhxy.manager.service.intf.EquipmentRepairService;
import com.zhxy.manager.vo.PageBean;
import com.zhxy.manager.vo.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@RestController
@RequestMapping("/api/equipmentrepair/")
public class EquipmentRepairController {
    @Autowired
    private EquipmentRepairService service;
    //增
    @RequestMapping("save.do")
    public R save(EquipmentRepair equipmentRepair){
        return service.save(equipmentRepair);
    }
    //查全部
    @RequestMapping("page.do")
    public List<EquipmentRepair> page(){
        return service.queryPage();
    }
    //删除
    @PostMapping("del.do")
    public R del(int id){
        return service.del(id);
    }
    //修改
    @PostMapping("update.do")
    public R update(EquipmentRepair equipmentRepair){
        return service.update(equipmentRepair);
    }
    //条件查询
    @GetMapping("pagewhere.do")
    public PageBean page(String name,int page,int limit){
        return service.queryDetail(name,page,limit);
    }
    //批量删除 JSON格式的数据请求
    @PostMapping("delbatch.do")
    public R del(@RequestBody int[] ids){
        return service.delBatch(ids);
    }

    @GetMapping("downall.do")
    public void down(HttpServletResponse res) throws IOException {
        List<EquipmentRepair> list = service.queryPage();
        res.setHeader("Content-disposition", "attachment;filename=" +System.currentTimeMillis() + ".xlsx");
        //3.写出内容
        EasyExcel.write(res.getOutputStream(),EquipmentRepair.class).sheet().doWrite(list);
    }
}
